package com.education.project.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.education.project.model.LoginUserType;
import com.education.project.mapper.LoginUserMapper;
import com.education.project.mapper.LoginUserTypeMapper;
import com.education.project.mapper.WebNavResourcesMapper;
import com.education.project.service.LoginUserTypeService;

@Service
public class LoginUserTypeServiceImpl implements LoginUserTypeService {
	@Autowired
	private LoginUserTypeMapper loginUserTypeMapper;
	@Autowired
	private LoginUserMapper loginUserMapper;
	@Autowired
	private WebNavResourcesMapper webNavResourcesMapper;
	
	@Override
	public LoginUserType getLoginUserType(Integer loginUserTypeId) {
		return loginUserTypeMapper.get(loginUserTypeId);
	}

	@Override
	public List getAllLoginUserType() {
		return loginUserTypeMapper.getall();
	}
	
	@Override
	@Transactional
	public void updateUserTypeNav(Integer loginUserTypeId, List list) {
		webNavResourcesMapper.clearUserTypeNavResources(loginUserTypeId);
		if(list.size()>0) {
			webNavResourcesMapper.saveUserTypeNavResources(list);
		}
	}

	@Transactional
	@Override
	public void saveLoginUserType(LoginUserType loginUserType) {
		loginUserTypeMapper.save(loginUserType);
	}

	@Transactional
	@Override
	public void updateLoginUserType(LoginUserType loginUserType) {
		loginUserTypeMapper.update(loginUserType);
	}

	@Transactional
	@Override
	public void removeLoginUserType(Integer loginUserTypeId) {
		loginUserTypeMapper.remove(loginUserTypeId);
	}
	
	@Override
	public Integer getLoginUserCountByUserType(Integer usertypeid) {
		return loginUserMapper.getLoginUserCountByUserType(usertypeid);
	}
}
